<template>
  <div class="persondata">
    <!-- 标题 -->
    <div class="nav-text">个人资料</div>
    <el-divider />
    <!-- 主体 -->
    <div class="user-infos">
      <!-- 主要信息 -->
      <!-- 信息展示 -->
      <div class="info-show">
        <UserinfoShow :userinfo="userinfo" v-if="userinfo && userinfoFlag"></UserinfoShow>
      </div>
      <!-- 信息修改 -->
      <div class="info-input">
        <!-- <UserinfoInput></UserinfoInput> -->
      </div>
      <!-- 头像 -->
      <div class="avatar">
        <UserPic :action="userpicUrl" :userPic="userPic" v-if="userPic !== '' && userPicFlag"></UserPic>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue"
import Service from "@/utils/axios"

import UserinfoShow from './components/UserinfoShow/index.vue'
import UserinfoInput from './components/UserinfoInput/index.vue'
import UserPic from './components/UserPic/index.vue'

// 项目封面上传的后端地址
const userpicUrl = ref('/bkapi/api/uploadimgUserPic')
// let userpicUrl = ref(
//   'http://127.0.0.1:3000/api/uploadimgPublishProCover'
// );

const userPic = ref('');
const userPicFlag = ref(false);
const userinfo = ref({});
const userinfoFlag = ref(false)
// 获取用户信息方法
const getUserinfoFunc = async () => {
  const username = localStorage.getItem('username');
  console.log('获取当前用户信息', username);
  await Service.get(`/bkapi/userinfo/getUserinfoByUsername?username=${username}`)
    .then((res: any) => {
      console.log('data', res?.data);
      userinfo.value = { ...res?.data?.data };
      userPic.value = res?.data?.data?.user_pic;
      userPicFlag.value = true;
      userinfoFlag.value = true;
    })

}

onMounted(() => {
  // 获取用户信息方法
  getUserinfoFunc()
})
</script>

<style lang="less" scoped>
.persondata {
  .nav-text {
    font-weight: 600;
    font-size: 20px;
    line-height: 18px;
    color: #333;
    margin-bottom: 20px;
  }

  .user-infos {
    display: flex;
  }

  .avatar {
    padding: 40px;
  }
}
</style>
<style>
.disUoloadBtn .el-upload--picture-card {
  display: none;
  /* 上传按钮隐藏 */
}
</style>